/*
 * @Author: Soulmate
 * @Date: 2023-09-19 10:25:34
 * @LastEditTime: 2023-09-19 10:31:58
 * @LastEditors: Soulmate
 * @Description:
 * @FilePath: \ruoyi-ui-vue3\src\views\index\workspace\hook.tsx
 * 版权声明
 */
import { listVersion, listTask, listProgram, listTeam } from '@/api/index/workspace';

import { useSortAble } from '@/utils/sortable';

export function easyHookData() {
    const versionData = ref([]); // 版本信息
    const taskData = ref([]); // 我的任务
    const programData = ref([]); // 我的任务
    const teamData = ref([]); // 我的任务
    const duringNum = ref(0); // 进度
    const duringToNum = ref(0); // 进度
    let timer = null;
    const programShow = computed(() => {
        return duringToNum.value > 100
            ? { text: '你真棒，已完成目标！', status: 'success' }
            : 79 < duringToNum.value && duringToNum.value < 100
            ? { text: '加油，就差一点了！', status: 'warning' }
            : { text: '很遗憾，您为达成目标！', status: 'exception' };
    });

    const getVersionList = async () => {
        listVersion({ total: 10 }).then(({ data }) => {
            versionData.value = data;
        });
    };

    const getTaskList = async () => {
        listTask({ total: 10 }).then(({ data }) => {
            taskData.value = data;
        });
    };

    const getProgramList = async () => {
        listProgram({ total: 10 }).then(({ data }) => {
            programData.value = data;
        });
    };

    const getTeamList = async () => {
        listTeam({ total: 10 }).then(({ data }) => {
            teamData.value = data;
        });
    };
    const sortTable = () => {
        // 获取el-table DOM
        useSortAble(document.querySelector('.el-table__body-wrapper table tbody'), '.drag_btn');

        Interval();
    };

    const Interval = () => {
        timer = setInterval(() => {
            if (duringNum.value < duringToNum.value) {
                duringNum.value++;
            } else {
                clearInterval(timer);
            }
        }, 10);
    };
    return {
        taskData,
        teamData,
        duringNum,
        duringToNum,
        versionData,
        programData,
        programShow,
        getVersionList,
        getTaskList,
        getProgramList,
        getTeamList,
        sortTable,
    };
}
